{% extends "blog/base.html" %}
{% block title %}{{ post.title}}{% endblock %}
{% block body %}
  <div class="row">
    <div class="col-lg-9">
      <!--标题行-->
      <div class="row"> 
        <div class="col-lg-12"><h1>{{ post.title }}</h1></div>
      </div>
      <!--作者时间与标签-->
      <div class="row">
        <div class="col-lg-6">
          <p>作者: <a href="{{ url_for('.user', username=post.user.username) }}">{{ post.user.username }}</a>发表日期:{{post.publish_date }}</p>
        </div>
        <div class="col-lg-6">
          <p class="text-rigth"> 标签: {% for tag in tags %}
            <a href="{{ url_for('.tag', tag_name=tag.title) }}">{{ tag.title }}</a>
            {% endfor %}
          </p>
        </div>
      </div>
      <!--正文-->
      <div class="row">
        <div class="col-lg-12">
          {{ post.text | safe }}
        </div>
      </div>
      <!--评论-->
      <div class="row">
        <h1>&nbsp;评论数({{ comments | length }})</h1>
        <div class="col-lg-12">
          <h3>新的评论:</h3>
          <form method="POST" action="{{ url_for('.post', post_id=post.id) }}">
            {{ form.hidden_tag() }}
            <div class="form-group">
              {{ form.name.label }}
              {% if form.name.errors %}
                {% for e in form.name.errors %}
                  <p class="help-block">{{ e }}</p>
                {% endfor %}
              {% endif %}
              {{ form.name(class_='form-control') }}
            </div>
            <div class="form-group">
              {{ form.text.label }}
              {% if form.text.errors %}
                {% for e in form.text.errors %}
                  <p class="help-block">{{ e }}</p>
                {% endfor %}
              {% endif %}
              {{ form.text(class_='form-control') }}
            </div>
            <input class="btn btn-primary" type="submit" value="发表评论">
          </form>
        </div>
        <div class="col-lg-12">
          {% if comments | length == 0 %}
          <p>这篇文章还没有评论，快来发表你的高见！<p>
          {% else %}
            {% for comment in comments %}
              <div class="well">
                <p>{{ comment.name }} 发表于 {{ comment.date }}</p>
                <p>{{ comment.text }}</p>
              </div>
            {% endfor %}
          {% endif %}
        </div>
      </div>
    </div>
    <div class="col-lg-3">
      <div class="row">
        <h5>最近的文章</h5>
        <ul>
          {% for post in recent %}
            <li><a href="{{ url_for('.post', post_id=post.id) }}">{{ post.title }}</a></li>
          {% endfor %}
        </ul>
      </div>
      <div class="row">
        <h5>&nbsp;&nbsp;&nbsp;&nbsp;热门标签</h5>
        <ul>
          {% for tag in top_tags %}
            <li><a href="{{ url_for('.tag', tag_name=tag[0].title) }}">{{ tag[0].title }}</a></li>
          {% endfor %}
        </ul>
      </div>
    </div>
  </div>
{% endblock %}